import { mapState } from 'vuex';
export const langMixins = {
  data() {
      return {
          // lang: 'zh'
      }
  },
  computed: {
    ...mapState({
      lang: (state) => state.i18nData.lang
    })
  },
  mounted() {
    this.$i18n.locale = this.lang
  },
  methods: {
    setRouteByLang(menuRoutes, key = 'name', value = 'path') {
      menuRoutes.forEach(item => {
        item[key] = this.transI18n(item[value])
      })
      return menuRoutes
    },
    transI18n(param) {
      let data = ''
      if (param.includes('/')) {
        let dataArr = param.split('/')
        data = this.$t('nav.' + dataArr[dataArr.length - 1]).name
      } else {
        data = this.$t('nav.' + param).name
      }
      return data
    }
  }
}